function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var t = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
        var i = arguments[t];
        for (var a in i) Object.prototype.hasOwnProperty.call(i, a) && (e[a] = i[a]);
    }
    return e;
}, i = e(require("../../../utils/api2")), a = e(require("../../../utils/util")), s = e(require("../../../utils/config")), n = require("../../../public/pages/signin-page/checkIfNeedSignin"), o = getApp();

Page({
    limit: 10,
    data: {
        app: o.globalData.app,
        scrollActiveIndex: 0,
        isViewListInited: !1
    },
    handleRedirect: function(e) {
        e.scene && (wx.showLoading({
            title: "正在跳转",
            mask: !0
        }), i.default.v4.weapp.getdatafromscene({
            data: {
                scene: e.scene,
                app: o.globalData.app
            },
            complete: wx.hideLoading
        }).then(function(e) {
            var n = e.type, o = e.params, r = o.redirect, c = void 0;
            "loginpc" === n ? (wx.switchTab({
                url: "/pages/index/index"
            }), i.default.site.site.loginpc({
                data: {
                    scene: o.scene,
                    op: "login"
                }
            })) : (c = "thirdparty" === r ? "/pages/site-create/create/create?mode=create" : "0" === n ? "/pages/website/index/index?sid=" + o.sid : a.default.createModelUrl(s.default.model, t({}, o, {
                modid: n
            })), wx.navigateTo({
                url: c
            }));
        }));
    },
    onLoad: function(e) {
        "wxwork" === o.globalData.environment && this.$route("/pages/common/binding-site/binding-site", "redirect"), 
        this.handleRedirect(e), this.loadData(), this.addEventListener();
    },
    onShow: function() {
        a.default.updateViewSiteStatus(), a.default.getCardInfo();
    },
    addEventListener: function() {
        var e = this;
        this.$addListener("update:viewlist", function() {
            e.loadViewList();
        }), this.$addListener("site:focus", function(t) {
            t.status;
            e.loadFocusList();
        });
    },
    loadData: function() {
        var e = this;
        if (!this.loading) {
            this.loading = !0;
            var t = function() {
                e.loading = !1, wx.stopPullDownRefresh(), wx.hideLoading();
            };
            wx.showLoading({
                title: "加载中"
            }), this.loadViewList().then(function() {
                e.setData({
                    isViewListInited: !0
                });
            }), Promise.all([ this.loadFocusList(), this.loadCaseData() ]).then(function() {
                t();
            }).catch(function() {
                t();
            });
        }
    },
    loadViewList: function() {
        var e = this;
        return i.default.site.site.getviewlists({
            data: {
                offset: 0,
                limit: this.limit
            }
        }).then(function(t) {
            e.setData({
                viewlist: t.lists
            });
        });
    },
    loadFocusList: function() {
        var e = this;
        return i.default.site.focus.mylists({
            data: {
                limit: 10,
                offset: 0
            }
        }).then(function(t) {
            e.setData({
                focuslist: t.lists
            });
        });
    },
    loadCaseData: function() {
        var e = this;
        return new Promise(function(t) {
            i.default.site.site.getcaselistsv2({
                data: {}
            }).then(function(i) {
                var a = i.lists;
                e.setData({
                    caseCateList: e.__normalizeList(a)
                }), t(a);
            });
        });
    },
    __normalizeList: function(e) {
        if (e.length) return e.forEach(function(e) {
            e.cases.forEach(function(e) {
                var t = "";
                switch (+e.version) {
                  case 0:
                    t = "单页展示型";
                    break;

                  case 1:
                    t = "企业官网型";
                    break;

                  case 2:
                    t = "企业电商型";
                    break;

                  case 3:
                    t = "企业展示型";
                    break;

                  case 4:
                    t = "服务预约型";
                    break;

                  case 5:
                    t = "全功能旗舰型";
                }
                e.versiontext = t;
            });
        }), e || [];
    },
    switchCaseCate: function(e) {
        var t = e.currentTarget.dataset.index;
        this.setData({
            scrollActiveIndex: +t
        });
    },
    viewSite: function(e) {
        var t = e.currentTarget.dataset.sid;
        this.$route("/pages/website/index/index?sid=" + t + "&op=view");
    },
    guideToCerateSite: function() {
        this.setData({
            isFocus: !1,
            searchValue: "",
            searchList: []
        }), this.$route("/pages/site-create/index/index?mode=create");
    },
    create: function() {
        var e = this;
        if (!(0, n.askForSignin)()) {
            var t = {
                from: 1
            };
            a.default.collectSiteCreatData({
                node: "create",
                params: t
            }).then(function(t) {
                var i = t.stepid;
                e.$route("/pages/site-create/index/index?mode=create&stepid=" + i);
            });
        }
    },
    onPullDownRefresh: function() {
        this.loadData();
    },
    onShareAppMessage: function() {
        return {
            title: "让你拥有一个自己的小官网",
            path: "/pages/track/index/index"
        };
    }
});